"""
后台创建普通用户
"""
"""
后台创建管理员用户

"""
from app import app
from apps.user.models import User
from exts import db
from utils.md5 import md5


def create_superuser(username, password):
    user = User()
    user.username = username
    user.password = md5(password)[0:20]
    user.phone = username
    ret = User.query.filter(User.username == username).first()
    if ret:
        return '当前用户%s已经存在,无法创建' % username
    # 添加并提交
    db.session.add(user)
    db.session.commit()


username = '19803630852'
password = '123456'
with app.app_context():
    ret = create_superuser(username=username, password=password)
    print(ret)
